home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / net_src.arc / mulport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-08  |  9.9 KB  |  241 lines

  1. #include "config.h"
  2. #ifdef MULPORT
  3. #include <stdio.h>
  4. #include "global.h"
  5. #include "mbuf.h"
  6. #include "iface.h"
  7. #include "ax25.h"
  8. #include <ctype.h>
  9.  
  10. /**************************************************************************
  11. * The struct mulrep holds calls and interface names for multiport         *
  12. * repeating                                                               *
  13. * port[] holds the interface name passed back to hack in ax25.c           *
  14. **************************************************************************/
  15. typedef struct {
  16.      struct    ax25_addr dcall;    /* digipeater callsign */
  17.      char port[4];            /* port name */
  18. } mulrep;
  19.  
  20.  
  21. #define TRUE 1
  22. #define FALSE 0
  23.  
  24.  
  25.  
  26. /****************************************************************************
  27. * Multiport system globals                                                  *
  28. * mport is the multiport flag initialized to false until mulport is called. *
  29. ****************************************************************************/
  30. int       mport = FALSE;
  31. mulrep    destrpt[10], extbl[10], lan;
  32.  
  33. /*************************************************************************
  34. * mulport fills the array of structures of digi calls to which packets   *
  35. * may  be repeated and sets the global flag mport TRUE. It reads from    *
  36. * the file DIGILIST which must be in the ROOT directory and is formatted *
  37. * <callsign+ssid> <interface_name>                                       *
  38. * example:                                                               *
  39. * KE4ZV-1 ax0                                                            *
  40. * KD4NC-1 ax1                                                            *
  41. * mulport also builds an array of destination calls from the file EXLIST *
  42. * in the root directory for destinations not fitting the general rules.  *
  43. * This is the function called when the command "mulport on" is given.    *
  44. *************************************************************************/
  45. int mulport(argc,argv)
  46. int argc;
  47. char *argv[];
  48. {
  49.  FILE *fp, *fopen();
  50.  int       x;
  51.  char tcall[12], tport[4];
  52.  char str[257];
  53.  int tmp;
  54.  
  55.  if (strncmp(argv[1],"on",2)==0){
  56.       if ((fp = fopen("/digilist","r")) == 0) {
  57.           printf("Could not open file DIGILIST\n");
  58.           return(FALSE);
  59.       }
  60.       setcall(&(lan.dcall),"lan");
  61.       strcpy(lan.port,"");
  62.       printf("\nDigi Call          Interface\n");
  63.       for (x=0; (x <= 9) && (fgets(str, 256, fp)); x++) {
  64.           /* make sure we clear out the whole line to the \n   */
  65.           /* otherwise, any other  whitespace after the port  */
  66.           /* designator will fubar the parser                 */
  67.           tmp = sscanf(str, "%s %s", tcall, tport);
  68.           if (tmp!= 2) {    /* make sure we don't do a partial entry */
  69.             printf("Invalid record in DIGILIST encountered, record ignored\n");
  70.             continue;
  71.           }
  72.           printf("%9.9s       %6.6s\n",tcall,tport);
  73.  
  74. /*  we really need to verify that the port  exists before we put it into the
  75.     table or direct a stream to it. Current default behavior is to send the
  76.     packet back out the port it came in on if there is no match.
  77. */
  78.           setcall(&(destrpt[x].dcall),tcall);
  79.           strcpy(destrpt[x].port,tport);
  80. #ifdef MULBUG
  81.           printf("%9.9s      %6.6s\n",destrpt[x].dcall.call,destrpt[x].port);
  82. #endif
  83.      }
  84.       fclose(fp);
  85. /*finish out the array with null entries */
  86.       strcpy(tcall,'\0');
  87.       strcpy(tport,'\0');
  88.       for(;x<=9;x++){
  89.           setcall(&(destrpt[x].dcall),tcall);
  90.           strcpy(destrpt[x].port,tport);
  91.       }
  92.       /*****************************************************************
  93.       *    This code builds the exception list extbl[]                 *
  94.       *    This list handles destination calls who need behavior that  *
  95.       *    does not follow the mulport rules ie: a user station on the *
  96.       *    high speed trunk.                                           *
  97.       *****************************************************************/
  98.       if ((fp = fopen("/exlist","r")) == 0) {
  99.           printf("Could not open file EXLIST\n");
  100.           return(FALSE);
  101.       }
  102.       printf("\nException Call          Interface\n");
  103.       for (x=0; (x <= 9) && (fgets(str, 256, fp)); x++) {
  104.           tmp = sscanf(str, "%s %s", tcall, tport);
  105.           if (tmp!= 2) {    /* make sure we don't do a partial entry */
  106.             printf("Invalid record in EXLIST encountered, record ignored\n");
  107.             continue;
  108.           }
  109.           printf("%9.9s       %6.6s\n",tcall,tport);
  110.           setcall(&(extbl[x].dcall),tcall);
  111.           strcpy(extbl[x].port,tport);
  112. #ifdef MULBUG
  113.           printf("%9.9s      %6.6s\n",extbl[x].dcall.call,extbl[x].port);
  114. #endif
  115.      }
  116.       fclose(fp);
  117. /*finish out the array with null entries */
  118.       strcpy(tcall,'\0');
  119.       strcpy(tport,'\0');
  120.       for(;x<=9;x++){
  121.           setcall(&(destrpt[x].dcall),tcall);
  122.           strcpy(destrpt[x].port,tport);
  123.       }
  124.       mport = TRUE;
  125.       return(TRUE);
  126.  } else {
  127.      mport = FALSE;
  128.      return(FALSE);
  129.  }
  130.  
  131. }
  132.  
  133. /**************************************************************************
  134. * Here is the repeater hack called from ax_recv in module ax25.c.         *
  135. * Repeater searches the array of digi calls created by mulport for the    *
  136. * digi call following ours in the packet header. If a match occurs the    *
  137. * corresponding interface name is found by comparing the string in        *
  138. * port[] to the names assigned to interfaces with the attach command.     *
  139. * A pointer to the interface is returned by repeater. Default behavior on *
  140. * match failure is to return a pointer to the interface the packet came   *
  141. * in on. If our call is the last digi call in the header, the destination *
  142. * call is compared to the array of exception calls and, if a match, the   *
  143. * corresponding interface is returned by repeater. Default behavior on    *
  144. * match failure is to return a pointer to the interface referenced by the *
  145. * pseudo call "lan" in digilist.                                          *
  146. * If no matches at all are found, default behavior is to return a pointer *
  147. * to the interface the packet came in on.                                 *
  148. **************************************************************************/
  149. struct interface *
  150. repeater(ap,interface,hdr)
  151.      struct ax25_addr *ap;
  152.      struct interface *interface;
  153.      struct ax25 *hdr;
  154.  
  155. {
  156.      struct interface *intport;
  157.      int x, flg, match;
  158.  
  159.  if (++ap < &hdr->digis[hdr->ndigis]){
  160. #ifdef MULBUG
  161.                   printf("mport && there is a call after ours\n");
  162. #endif
  163.                   for (x=0, flg=0; (!flg) && (x <= 9) && (strcmp('\0',&(destrpt[x].dcall.call))!=0); x++){  /* 10 mports max */
  164. #ifdef MULBUG
  165.                     printf("stepping thru destrpt at %d %9.9s   %9.9s\n",x,ap->call,&(destrpt[x].dcall.call));
  166. #endif
  167.                       if (addreq(ap,&(destrpt[x].dcall))){
  168. #ifdef MULBUG
  169.                          printf("dcall match\n");
  170. #endif
  171.                          for (intport=ifaces; !flg && (intport!=NULLIF); intport=intport->next){
  172. #ifdef MULBUG
  173.                              printf("stepping thru interfaces %9.9s  %9.9s\n",intport->name,&(destrpt[x].port));
  174. #endif
  175.                              if (strcmp(intport->name,&(destrpt[x].port))==0){
  176. #ifdef MULBUG
  177.                                 printf("interface match on %s\n",&(destrpt[x].port));
  178. #endif
  179.                                 interface=intport;
  180.                                 flg = 1;
  181.                              }
  182.                          }
  183.                       }
  184.                   }
  185.                   ap--;
  186.                }
  187.                else{
  188.                    for (match=0,x=0, flg=0; (!flg) && (x <= 9) && (strcmp('\0',&(extbl[x].dcall.call))!=0); x++){  /* 10 mports max */
  189. #ifdef MULBUG
  190.                        printf("scanning for hdr.dest %9.9s  %9.9s\n",&(hdr->dest.call),&(extbl[x].dcall.call));
  191. #endif
  192.                        if (addreq(&(hdr->dest),&(extbl[x].dcall))){
  193. #ifdef MULBUG
  194.                           printf("dest match\n");
  195. #endif
  196.                           for (intport=ifaces; !flg && (intport!=NULLIF); intport=intport->next){
  197. #ifdef MULBUG
  198.                               printf("stepping thru interfaces %9.9s  %9.9s\n",intport->name,&(extbl[x].port));
  199. #endif
  200.                               if (strcmp(intport->name,&(extbl[x].port))==0){
  201. #ifdef MULBUG
  202.                                  printf("interface match\n");
  203. #endif
  204.                                  interface=intport;
  205.                                  flg = 1;
  206.                                  match=1;
  207.                               }
  208.                           }
  209.                       }
  210.                     }
  211.                     if (match!=1){
  212.                        for (x=0, flg=0; (!flg) && (x <= 9) && (strcmp('\0',&(destrpt[x].dcall.call))!=0); x++){  /* 10 mports max */
  213. #ifdef MULBUG
  214.                             printf("scanning for lan.dcall %9.9s  %9.9s\n",&(lan.dcall.call),&(destrpt[x].dcall.call));
  215. #endif
  216.                             if (addreq(&(lan.dcall),&(destrpt[x].dcall))){
  217. #ifdef MULBUG
  218.                                  printf("dcall match\n");
  219. #endif
  220.                                  for (intport=ifaces; !flg && (intport!=NULLIF); intport=intport->next){
  221. #ifdef MULBUG
  222.                                       printf("stepping thru interfaces %9.9s  %9.9s\n",intport->name,&(destrpt[x].port));
  223. #endif
  224.                                       if (strcmp(intport->name,&(destrpt[x].port))==0){
  225. #ifdef MULBUG
  226.                                           printf("interface match\n");
  227. #endif
  228.                                           interface=intport;
  229.                                           flg = 1;
  230.                                       }
  231.                                    }
  232.                              }
  233.                          }
  234.                       }
  235.                       ap--;
  236.                   }
  237. return(interface);
  238. }
  239. #endif
  240.  
  241.